﻿using UnityEngine;
using System.Collections;

public class ProjectileMovement : MonoBehaviour {

	// Use this for initialization

    //This is the script for making the bullets move. It has a public variable to adjust how fast they shoot.

    public float speed = 10;
	private GameObject planet;
	public int damageToPlanet;
	public int planetDamage = 5;

 	void Start()
    {
		planet = GameObject.FindGameObjectWithTag("Planet");

		if (this.gameObject.tag != "EnemyPlanetBullet")
			rigidbody.velocity = transform.forward * speed;
	}

	void Update()
	{
		if (this.gameObject.tag == "EnemyPlanetBullet")
			this.transform.position = Vector3.MoveTowards(this.transform.position, planet.transform.position, Time.deltaTime * speed);
	}

	void OnTriggerEnter(Collider other){
		if (other.tag == "Planet") {

			GameManager.planetHealth-=planetDamage;

			// disable the renderer, collider, and destroy the ship
			renderer.enabled = false;
			collider.enabled = false;
			Destroy(this.gameObject,0);
		}
	}
}
